﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using PPI.Client;
using PPI.Client.Logic;
using PPI.Client.Utils;
using PPI.Entities;
using PPI.Entities.Lookup;
using PPI.General;
using VMind.Global;

namespace PPIControls.Map
{
    public partial class GPSFilter : UserControl
    {
        private List<EVendor_Visit_Type> m_VisitTypes;
        private List<EXMissionStructures_TopType> m_Toptypes;
        private List<EXMissionStructures_PoleClass> m_Classes;
        private List<EXMissionStructures_PoleSpecies> m_Species;
        private List<EXMissionStructures_PoleTreatment> m_Treatments;


        public void LoadList()
        {
            m_VisitTypes = LCacheDataSingleton.Instance.VisitTypes;
            DropdownHelper.FillListBox(lstVisitTypes, m_VisitTypes, typeof(EVendor_Visit_Type), "Name", "Vendor_Visit_TypeId", "");

            m_Toptypes = LCacheDataSingleton.Instance.TopTypes;
            DropdownHelper.FillListBox(lstTopTypes, m_Toptypes, typeof(EXMissionStructures_TopType), "Name", "XMissionStructures_TopTypeId", "");
            DropdownHelper.FillListBox(lstPoleTopTypes, m_Toptypes, typeof(EXMissionStructures_TopType), "Name", "XMissionStructures_TopTypeId", "");

            m_Classes = LCacheDataSingleton.Instance.Class;
            DropdownHelper.FillListBox(lstPoleClasses, m_Classes, typeof(EXMissionStructures_PoleClass), "Name", "Id", "");

            
            m_Species = LCacheDataSingleton.Instance.Specie;
            DropdownHelper.FillListBox(lstPoleSpecies, m_Species, typeof(EXMissionStructures_PoleSpecies), "Name", "Id", "");

            
            m_Treatments = LCacheDataSingleton.Instance.Treatment;
            DropdownHelper.FillListBox(lstPoleTreatments, m_Treatments, typeof(EXMissionStructures_PoleTreatment), "Name", "Id", "");

            DataTable dtYears = FillSpecificDataTableHelper.FillDataTable(1944, DateTime.Now.Year, 1);
            DropdownHelper.FillListBox(lstYears, dtYears, "Name","Id","");


        }

        public GPSFilter()
        {
            InitializeComponent();
        }

        public void ClearSelectedItems()
        {
            DropdownHelper.ResetComboIndex(lstVisitTypes);
            DropdownHelper.ResetComboIndex(lstTopTypes);
            DropdownHelper.ResetComboIndex(lstPoleTopTypes);
            DropdownHelper.ResetComboIndex(lstPoleClasses);
            DropdownHelper.ResetComboIndex(lstPoleSpecies);
            DropdownHelper.ResetComboIndex(lstPoleTreatments);
            DropdownHelper.ResetComboIndex(lstYears);


        }

        public List<EVendor_Visit_Type> SelectedVisitTypes()
        {
            List<EVendor_Visit_Type> returnVisitTypeList = new List<EVendor_Visit_Type>();

            foreach (ListBoxItem item in lstVisitTypes.SelectedItems)
            {
                returnVisitTypeList.Add(new EVendor_Visit_Type(ConvertHelper.ToInt32(item.Value), item.Text));
            }
            return returnVisitTypeList;
        }

        public List<EXMissionStructures_TopType> SelectedToptypes()
        {
            List<EXMissionStructures_TopType> returnToptypeList = new List<EXMissionStructures_TopType>();

            foreach (ListBoxItem item in lstTopTypes.SelectedItems)
            {
                returnToptypeList.Add(new EXMissionStructures_TopType(ConvertHelper.ToInt32(item.Value), item.Text));
            }
            return returnToptypeList;
        }

        public List<EXMissionStructures_PoleSpecies> SelectedSpecies()
        {
            List<EXMissionStructures_PoleSpecies> returnSpeciesList = new List<EXMissionStructures_PoleSpecies>();

            foreach (ListBoxItem item in lstPoleSpecies.SelectedItems)
            {
                returnSpeciesList.Add(new EXMissionStructures_PoleSpecies(ConvertHelper.ToInt32(item.Value), item.Text));
            }
            return returnSpeciesList;
        }

        public List<EXMissionStructures_PoleClass> SelectedClasses()
        {
            List<EXMissionStructures_PoleClass> returnClassesList = new List<EXMissionStructures_PoleClass>();

            foreach (ListBoxItem item in lstPoleClasses.SelectedItems)
            {
                returnClassesList.Add(new EXMissionStructures_PoleClass(ConvertHelper.ToInt32(item.Value), item.Text));
            }
            return returnClassesList;
        }

        public List<EXMissionStructures_PoleTreatment> SelectedTreatments()
        {
            List<EXMissionStructures_PoleTreatment> returnTreatmentsList = new List<EXMissionStructures_PoleTreatment>();

            foreach (ListBoxItem item in lstPoleTreatments.SelectedItems)
            {
                returnTreatmentsList.Add(new EXMissionStructures_PoleTreatment(ConvertHelper.ToInt32(item.Value), item.Text));
            }
            return returnTreatmentsList;
        }

        public List<Int32> SelectedYears()
        {
            List<Int32> returnYearList = new List<Int32>();

            foreach (ListBoxItem item in lstYears.SelectedItems)
            {
                returnYearList.Add(ConvertHelper.ToInt32(item.Value));
            }
            return returnYearList;
        }

            

    }
}
